package base.controller;

import base.bean.UserEntity;
import base.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by uas on 2018/3/18.
 */
@Controller
@RequestMapping("/test")
public class LoginController {
    @Autowired
    IUserService iUserService;

    @RequestMapping("/login")
    private ModelAndView login(){
        ModelAndView login=new ModelAndView();
        login.setViewName("login");
        return  login;
    }

    @RequestMapping("/loginx")
    private ModelAndView loginAction(HttpServletRequest request, HttpServletResponse response){
        ModelAndView loginAction=new ModelAndView();
        String name=request.getParameter("username");
        String password=request.getParameter("password");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html, charset=utf-8");
        UserEntity user = iUserService.findByNameAndPassword(name, password);
        if(user != null){
            loginAction.setViewName("main");
            return loginAction;
        }else {


            return login();
        }
    }
}
